﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Dot5Demo
{
    public class TextRenderer : Render
    {
        public TextRenderer()
        {
            Font = new Font("微软雅黑", 12.0f);
            Color = Color.Red;
            Text = "输入文字";
            _brush = new SolidBrush(Color);
        }
        private Brush _brush;
        public string Text { get; set; }
        public Color Color { get; set; }

        public override void DoRender(Graphics g, Rectangle rect)
        {
            if (Font.Height != rect.Height/2)
            {
                Font.Dispose();
                Font = new Font("微软雅黑", rect.Height/2);
            }
            g.DrawString(Text, Font, _brush, rect);
        }

        public override void Dispose()
        {
            base.Dispose();
            _brush?.Dispose();
            Font?.Dispose();
        }
    }
}
